var member_id = store_id = '';
document.addEventListener('plusready',function(){
	member_id = plus.storage.getItem('id');
	store_id = plus.storage.getItem('store_id');
	var ws = plus.webview.currentWebview();
	var cart_id = ws.cart_id;
	plus.nativeUI.showWaiting('加载中...');
//	console.log(apiRoot+"?act=index&op=mobile&cart_id="+cart_id);
	$.ajax({ 
		type:"post", 
		url:apiRoot+"?act=index&op=mobile",
		data:{cart_id:cart_id,store_id:store_id},
		dataType:'json',
		success:function(data){  
			plus.nativeUI.closeWaiting();
			console.log(JSON.stringify(data));
			if(data.length > 0){
				var html = html3 = '';
				html += '<a class="mui-control-item mui-active" href="#item1mobile">全部</a>';
				$.each(data, function(k, v) {
					html += '<a class="mui-control-item" href="#item'+ (k+2) +'mobile">'+v.gc_name+'</a>';
						$.each(v.goods_details, function(key, value) {
							html3 += '<div class="mui-Gra">'+ 
										'<div class="mui-card-header Graduation" data-id="'+ value.goods_id +'" data-did="'+ value.store_id +'">'+
											'<img src="'+ pics + value.store_id + '/' + value.goods_image +'"/>'+
										'</div>'+
										'<div class="mui-card-content">'+
											'<div class="mui-card-content-inner">'+
												'<div class="frien_bq">	'+																			
													'<div class="mui-ellipsis"><button type="button" class="mui-btn mui-btn-success">租赁</button>'+ value.goods_name +'</div>	'+														
													'<b>￥'+ value.goods_price +'</b>'+													
												'</div>'+
											'</div>'+
										 '</div>'+ 
									  '</div>'; 
						});
				}); 
				$('#sliderSegmentedControl').html(html);
				$('#item1mobile').html(html3);	
				$.each(data, function(k, v) {
					var html2 = '<div id="item'+ (k+2) +'mobile" class="mui-slider-item mui-control-content">';
						$.each(v.goods_details, function(key, value) {
							html2 += '<div class="mui-Gra">'+
										'<div class="mui-card-header Graduation" data-id="'+ value.goods_id +'" data-did="'+ value.store_id +'">'+
											'<img src="'+ pics + value.store_id + '/' +value.goods_image +'"/>'+
										'</div>'+
										'<div class="mui-card-content">'+
											'<div class="mui-card-content-inner">'+
												'<div class="frien_bq">	'+																			
													'<div class="mui-ellipsis"><button type="button" class="mui-btn mui-btn-success">租赁</button>'+ value.goods_name +'</div>	'+														
													'<b>￥'+ value.goods_price +'</b>'+													
												'</div>'+
											'</div>'+
										 '</div>'+
									  '</div>';
						});
					html2 += '</div>';
					$('.mui-slider-group').append(html2);	
				});
			}
			//详情
			$('.Graduation').unbind('click');
			$('.Graduation').on('click',function(){
				var _this = $(this);
				var goodsid = _this.attr('data-id');
				var store_id = _this.attr('data-did');
				var nwaiting = plus.nativeUI.showWaiting();//显示原生等待框
				var webviewContent= plus.webview.create('./goods_details.html','goods_details.html',{},{goodsid:goodsid,store_id:store_id});//后台创建webview并打开show.html
				webviewContent.addEventListener("loaded", function() { //注册新webview的载入完成事件
			        nwaiting.close(); //新webview的载入完毕后关闭等待框
			        webviewContent.show("slide-in-right",500); //把新webview窗体显示出来，显示动画效果为速度200毫秒的右侧移入动画
			    }, false);
			})
		}, 
		error:function(e){
			plus.nativeUI.closeWaiting();
			toast('连接失败！');
		}
	});
},false);